{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "660c99d8",
   "metadata": {},
   "source": [
    "Question 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4da4a514",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87442\n"
     ]
    }
   ],
   "source": [
    "import csv\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "y=0\n",
    "for row in f:\n",
    "    if row[2]=='confidence':\n",
    "        pass\n",
    "    else:\n",
    "        x=float(row[2])\n",
    "        if x>=0.9:\n",
    "            y=y+1\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22855f32",
   "metadata": {},
   "source": [
    "Question 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ae7be020",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x_mean= 0.41027307219355996\n",
      "x_std= 0.2095228849903554\n",
      "y_mean= 0.43831972720236484\n",
      "y_std= 0.21608766176112518\n",
      "120036\n"
     ]
    }
   ],
   "source": [
    "#第二题\n",
    "\n",
    "#计算x的均值和标准差\n",
    "import csv\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "sum1=0\n",
    "sum2=0\n",
    "count=0\n",
    "y=0\n",
    "for row in f:\n",
    "    if row[3]=='norm_pos_x':\n",
    "        pass\n",
    "    else:\n",
    "        x=float(row[3])\n",
    "        sum1=sum1+x\n",
    "        count=count+1\n",
    "mean1=sum1/count\n",
    "print(\"x_mean=\",mean1)\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "for row in f:\n",
    "    if row[3]=='norm_pos_x':\n",
    "        pass\n",
    "    else:\n",
    "        x=float(row[3])\n",
    "        sum2=sum2+(x-mean1)**2\n",
    "fc1=sum2/count\n",
    "std1=fc1**0.5\n",
    "print(\"x_std=\",std1)\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "#计算y的均值和标准差\n",
    "sum1=0\n",
    "sum2=0\n",
    "count=0\n",
    "y=0\n",
    "for row in f:\n",
    "    if row[4]=='norm_pos_y':\n",
    "        pass\n",
    "    else:\n",
    "        x=float(row[4])\n",
    "        sum1=sum1+x\n",
    "        count=count+1\n",
    "mean2=sum1/count\n",
    "print(\"y_mean=\",mean2)\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "for row in f:\n",
    "    if row[4]=='norm_pos_y':\n",
    "        pass\n",
    "    else:\n",
    "        x=float(row[4])\n",
    "        sum2=sum2+(x-mean2)**2\n",
    "fc2=sum2/count\n",
    "std2=fc2**0.5\n",
    "print(\"y_std=\",std2)\n",
    "#根据3sigma原则筛选\n",
    "y=0\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "for row in f:\n",
    "    if row[4]=='norm_pos_y':\n",
    "        pass\n",
    "    else:\n",
    "        x=float(row[3])\n",
    "        if mean1-3*std1<x<mean1+3*std1:\n",
    "            z=float(row[4])\n",
    "            if mean2-3*std2<z<mean2+3*std2:\n",
    "                y=y+1\n",
    "        else:\n",
    "            pass\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01d5875d",
   "metadata": {},
   "source": [
    "Question 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d93cfa07",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-02T08:29:10.77678+0000\n",
      "1970-01-02T08:29:10.776787+0000\n",
      "1970-01-02T08:29:10.779709+0000\n",
      "1970-01-02T08:29:10.779759+0000\n",
      "1970-01-02T08:29:10.787485+0000\n",
      "1970-01-02T08:29:10.78757999999+0000\n",
      "1970-01-02T08:29:10.7894805+0000\n",
      "1970-01-02T08:29:10.7935835+0000\n",
      "1970-01-02T08:29:10.7956825+0000\n",
      "1970-01-02T08:29:10.79840649999+0000\n",
      "1970-01-02T08:29:10.80114+0000\n",
      "1970-01-02T08:29:10.80297349999+0000\n",
      "1970-01-02T08:29:10.8046305+0000\n",
      "1970-01-02T08:29:10.80726949999+0000\n",
      "1970-01-02T08:29:10.8097485+0000\n",
      "1970-01-02T08:29:10.81287299999+0000\n",
      "1970-01-02T08:29:10.814136+0000\n",
      "1970-01-02T08:29:10.8159975+0000\n",
      "1970-01-02T08:29:10.818051+0000\n"
     ]
    }
   ],
   "source": [
    "#第三题\n",
    "import time\n",
    "import csv\n",
    "count=0\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "for row in f:\n",
    "    if row[0]=='gaze_timestamp':\n",
    "        pass\n",
    "    else:\n",
    "        x=row[0]\n",
    "        x=str(x)\n",
    "        b=x.split(\".\")\n",
    "        timeStamp = int(b[0])\n",
    "        timeArray = time.localtime(timeStamp)\n",
    "        otherStyleTime = str(time.strftime(\"%Y-%m-%dT%H:%M:%S\",timeArray))\n",
    "        row[0]=otherStyleTime+\".\"+b[1]+\"+0000\"\n",
    "        count=count+1\n",
    "        if count<20:\n",
    "            print(row[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16b3702e",
   "metadata": {},
   "source": [
    "Question 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f6eae9a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "采样率= 427.62610766083765\n"
     ]
    }
   ],
   "source": [
    "#第四题\n",
    "import csv\n",
    "x=0\n",
    "y=0\n",
    "count=0\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "for row in f:\n",
    "    if row[0]=='gaze_timestamp':\n",
    "        pass\n",
    "    elif count==0:\n",
    "        x=row[0]\n",
    "        count=count+1\n",
    "    else:\n",
    "        count=count+1\n",
    "        y=row[0]\n",
    "fps=count/(float(y)-float(x))\n",
    "print(\"采样率=\",fps)   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a89beac",
   "metadata": {},
   "source": [
    "Question 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d0dfc2ab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['88150.77678', '0', '0.8280059462620806', '0.5314327126985153', '0.39750946211500204', '88150.77678-0', '28.369752901573236', '52.033134560158175', '705.1211159195539', '20.0', '15.0', '-20.0', '0.01152676874215287', '0.051001789765111646', '0.9986320398640939', '', '', '', '', '', '']\n",
      "['88150.787485', '1', '0.5025948800258426', '0.3401089118572799', '0.14298949506249015', '88150.787485-1', '-139.4048601388959', '175.088321362755', '681.1514528333081', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.13698933743054134', '0.2204754503935745', '0.9657248558487515', '', '', '', '', '', '']\n",
      "['88150.79840649999', '1', '0.7084760742125342', '0.4941157090777496', '0.4071094106264913', '88150.79569-0 88150.801123-1', '2.1796287066650546', '-19.354529932692056', '-289.3865972267117', '20.0', '15.0', '-20.0', '0.06514516047431963', '0.027374145920454677', '0.9975002577452808', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1525226416003532', '0.22265933259715345', '0.9628913050841411']\n",
      "['88150.80726949999', '1', '0.8563407607235008', '0.49477736411660694', '0.4049685390557781', '88150.809749-0 88150.80479-1', '1.925754580585762', '-19.710658057686643', '-288.0721152448382', '20.0', '15.0', '-20.0', '0.066337739085217', '0.02383990799003523', '0.9975123874719999', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.15222844217062562', '0.22981420200416583', '0.9612553947580701']\n",
      "['88150.818051', '2', '0.8361660611207393', '0.49377224367345585', '0.40027023387364546', '88150.81599799999-0 88150.820104-1', '2.3258154849723436', '-20.950335079207825', '-291.7653248393765', '20.0', '15.0', '-20.0', '0.06396210553253093', '0.024893336791321347', '0.9976418048775022', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1515273956574198', '0.23414301276977342', '0.9603210389949675']\n",
      "['88150.827729', '2', '0.9151973420751922', '0.4935611049606477', '0.399305458229399', '88150.827729-0 88150.827729-1', '2.429836652393641', '-21.374412662746966', '-294.81920004608054', '20.0', '15.0', '-20.0', '0.06288346587545898', '0.02509974236087054', '0.9977052032804625', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.15024262070355351', '0.23411549682169422', '0.9605295878170852']\n",
      "['88150.83957499999', '2', '0.8981226615721961', '0.49344885948540396', '0.3984837010036957', '88150.83570099999-0 88150.84344899999-1', '2.469472786500136', '-21.52512256063822', '-294.4946166480155', '20.0', '15.0', '-20.0', '0.06281947395024938', '0.027157390027912388', '0.9976553462290907', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1505621238051983', '0.23344803725625876', '0.960642004482663']\n",
      "['88150.84749249999', '3', '0.8146346350814423', '0.49268465705635095', '0.3989208383436903', '88150.85153599999-0 88150.84344899999-1', '2.776177148200823', '-21.577277273604157', '-296.4848556983736', '20.0', '15.0', '-20.0', '0.061283019104364955', '0.02566851258753678', '0.9977903181686012', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1505621238051983', '0.23344803725625876', '0.960642004482663']\n",
      "['88150.8580525', '3', '0.8028764861728308', '0.49310060776833786', '0.3978841406342749', '88150.85654-0 88150.85956499999-1', '2.6335231752731048', '-21.92512270062688', '-298.20597403352224', '20.0', '15.0', '-20.0', '0.06140321642039546', '0.025916912799037132', '0.9977765073623442', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14915185946327889', '0.2340532138000838', '0.9607147422250263']\n",
      "['88150.86962', '3', '0.922197307158175', '0.49263493312230366', '0.3988137517485483', '88150.867514-0 88150.871726-1', '2.8137737507053764', '-21.744854170303462', '-298.47125345128484', '20.0', '15.0', '-20.0', '0.06071702183202721', '0.025219893820897885', '0.9978363594375146', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14964541784424926', '0.23325783877395026', '0.9608314261975022']\n",
      "['88150.87752149999', '4', '0.94500047108518', '0.4920943029105782', '0.3989300839628567', '88150.879586-0 88150.87545699999-1', '3.018227170856065', '-21.704819872309287', '-298.2646502338695', '20.0', '15.0', '-20.0', '0.06004036186469085', '0.024936294324659092', '0.9978844302686117', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1504509230615827', '0.2334355900843485', '0.9606624511408207']\n",
      "['88150.88828099999', '4', '0.8256068046453535', '0.49184939008427975', '0.39804174684568916', '88150.888291-0 88150.88827099999-1', '3.12305009056613', '-21.975246449045827', '-299.3497306930303', '20.0', '15.0', '-20.0', '0.059438980318556295', '0.02578240685975724', '0.9978989303106849', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1502346770715741', '0.23348674078640194', '0.9606838625074033']\n",
      "['88150.8975135', '4', '0.8550647363113325', '0.49150645479477334', '0.3989299375954948', '88150.89551599999-0 88150.899511-1', '3.2536311073442707', '-21.77831974188079', '-299.2742419323912', '20.0', '15.0', '-20.0', '0.05899829367017455', '0.024598649249555092', '0.9979549628110009', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.15072400756415755', '0.23336065221179728', '0.9606378503593769']\n",
      "['88150.90740649999', '4', '0.860093311910097', '0.49108884277345205', '0.3988032611048965', '88150.90741599999-0 88150.90739699999-1', '3.4153029561257977', '-21.8164544627108', '-299.42300047452966', '20.0', '15.0', '-20.0', '0.05839478901870607', '0.02400047627187978', '0.998005022910298', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.15118438109460267', '0.2340633438184941', '0.9603945199726763']\n",
      "['88150.917009', '5', '0.8383589621749243', '0.4916988785237518', '0.39698290407830483', '88150.91700999999-0 88150.91700799999-1', '3.2059927353378015', '-22.379871794808', '-301.72812572966956', '20.0', '15.0', '-20.0', '0.05864262281509698', '0.02531090342311198', '0.9979581158331612', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14925633872709826', '0.2345754008162153', '0.9605711460801297']\n",
      "['88150.9275245', '5', '0.853040894539125', '0.4914520921772419', '0.39748468234276335', '88150.927522-0 88150.92752699999-1', '3.323771199109265', '-22.422424924445156', '-303.7814987183897', '20.0', '15.0', '-20.0', '0.057815106883074265', '0.023935124425489368', '0.9980403414866735', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14860165931375657', '0.2343942415664973', '0.9607168606669007']\n",
      "['88150.93855949999', '5', '0.9987443957942154', '0.49116162292077215', '0.3963212280529863', '88150.93622799999-0 88150.94089099999-1', '3.444670660175696', '-22.729377983279125', '-304.48451442370134', '20.0', '15.0', '-20.0', '0.05725573600184664', '0.02556757341574248', '0.9980321036342059', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1486475062957136', '0.23424002017754897', '0.9607473818956195']\n",
      "['88150.947523', '6', '0.8036163788282745', '0.49162389357594083', '0.3961178880738129', '88150.947523-0 88150.947523-1', '3.262791263322139', '-22.761999060444996', '-304.32465222130315', '20.0', '15.0', '-20.0', '0.05791441579586018', '0.025849307221017352', '0.9979868404739706', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14811747558506844', '0.23433106058094225', '0.9608070396668197']\n",
      "['88150.95950249999', '6', '0.8391189191753998', '0.4910277786448531', '0.3974705782663642', '88150.963521-0 88150.95548399999-1', '3.4969272612392786', '-22.477999327919925', '-304.4925347585185', '20.0', '15.0', '-20.0', '0.057074997183387884', '0.023794625042328963', '0.9980862991323006', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1488208667257802', '0.23427704473976166', '0.9607115154587205']\n",
      "['88150.9674385', '6', '0.8927541387709003', '0.4908699620824434', '0.39666374561952633', '88150.96744-0 88150.967437-1', '3.5720576637630472', '-22.74160554313528', '-305.6581007674199', '20.0', '15.0', '-20.0', '0.05658413768984879', '0.024528738222491044', '0.9980964764806606', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1484760207186315', '0.23430510114919034', '0.9607580292909492']\n"
     ]
    }
   ],
   "source": [
    "#第五题\n",
    "import csv\n",
    "x=0\n",
    "y=0\n",
    "count=0\n",
    "f = csv.reader(open('gaze.csv','r'))\n",
    "for row in f:\n",
    "    if row[0]=='gaze_timestamp':\n",
    "        pass\n",
    "    elif count==0:\n",
    "        print(row)\n",
    "        x=float(row[0])\n",
    "        count=count+1\n",
    "    elif count/(float(row[0])-float(x))<=100:\n",
    "        print(row)\n",
    "        count=count+1\n",
    "    else:\n",
    "        pass\n",
    "    if count==20:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "562ef8c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
